/*
package com.dailyblue.example.springcloud.sentinel.consumer.handler;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
import com.dailyblue.example.springcloud.commons.util.JsonResult;
import com.dailyblue.example.springcloud.commons.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

//@Component
@Slf4j
public class MyBlockHandler implements BlockExceptionHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
        log.info("开始自定义异常返回");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        JsonResult result;
        // 限流异常
        if (e instanceof FlowException) {
            result = ResultTool.fail(501, "限制了流量,e:" + e.getMessage());
        } else if (e instanceof DegradeException) {
            result = ResultTool.fail(502, "服务降级,e:" + e.getMessage());
        } else if (e instanceof AuthorityException) {
            result = ResultTool.fail(503, "权限不符合,e:" + e.getMessage());
        } else if (e instanceof ParamFlowException) {
            result = ResultTool.fail(504, "参数流量限制,e:" + e.getMessage());
        } else {
            result = ResultTool.fail(505, "其他限制,e:" + e.getMessage());
        }
        out.write(result.toString());
    }
}
*/
